var b_lang;//=1，点击状态按钮
var SortJson = [];
var app_url=location.origin;
var EDITMODE=false; 
//日期格式化
var calendarDateFormat = myApp.calendar({
	input: '#arrivalTime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#transfer_arrivalTime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#transfer_arrivalTime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});

var calendarDateFormat = myApp.calendar({
	input: '#ecreatetime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#screatetime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#echecktime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
	input: '#schecktime',
    monthNames: ['01'+_('月'), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});


(function(){
	var apply = {
		init: function(){
			LoadBanks();
			this.bindEvents();
		},
		bindEvents:function(){
			var self = this;
			 //跳转页面
             $("#navMenu a").on("click",function(){
            	var link_url=$(this).attr("data-href");
            	if(APP){
            		var appJson={};
           			appJson.title=$(this).attr("data-title");
           			appJson.url=app_url+link_url;	
           			YiYi_APP.showNewPage(JSON.stringify(appJson));
            	}else{
            		location.href = link_url;
            	}
            });
			//点击行展开详情
			$("#stock_body").on("click", "tr td", function () {
			    var td_input = $(this).index();
			    if (td_input == 0 || td_input==8) {
			        //勾选框不展开详情
			    } else {
			        $(this).parent("tr").next(".stock_detail").slideToggle(0);
			    }
			});
			//申请
			$("#_apply").on('click',function(){
				myApp.popup(".applyflow_pop_box");
            	TjAccountLoad();//账户列表
			});
			//添加
			$("#_add").on('click',function(){
				myApp.popup(".add_pop_box");
			});
			
			
			//点击筛选按钮
			$("#show_term_btn").on("click", function () {
				myApp.popup(".user_filter_box");
			});
			//确定筛选
			$("#confirm_btn").on("click",function(){
				LoadBanks();//获取数据列表
				myApp.closeModal(".user_filter_box");
			});
			//状态筛选
			$("#_sysStatus>ul").on("click", "li", function () {
				$(this).addClass("add_blue").siblings().removeClass("add_blue");
				LoadBanks();//获取数据列表
			});			
			//列表的勾选框
			$("#stock_body").on("click",".check_list_box",function(){
				$(this).children("span").toggleClass("selected");
			});
			//排序方式
            $("#product_table_fixed th").on("click", function () {
				sortFun($(this));
            });
			
			//添加输入验证 12-8 class=_add
            var validate = $("._add").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form   
                    AddBank();//添加账户
                },
                rules: {
                    BankName:"required", 
                    BankAccount: "required", 
                    BankBalance:"required", 
                    Currency:"required",
                },
                messages: {
                    BankName:"",
                    BankAccount: "",
                    BankBalance:"",
                    Currency:"",
                }
            });

            //直接充值输入验证 01-05
            var validate = $("._rech").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form  
                    DirectCharge();//直接充值
                },
                rules: {                    
                    BankID:"required", 
                    BankBalance:"required", 
                    Amount:"required",
                    Comments:"required",                    
                },
                messages: {
                    BankID:"",
                    BankBalance:"", 
                    Amount:"",
                    Comments:"",
                }
            });  

            //换美金输入验证 01-03
            var validate = $("._exchan").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form  
                    AddExchange();//添加兑换
                },
                rules: {                    
                    Exchange:"required", 
                    ExBalance: "required", 
                    BankID:"required", 
                    ExAmount:"required", 
                    Amount:"required",   
                    Others:"required", 
                    CreateTime:"required", 
                    ArrivalTime:"required", 
                },
                messages: {
                    Exchange:"",
                    ExBalance: "",
                    BankID:"",
                    ExAmount:"",
                    Amount:"",  
                    Others:"", 
                    CreateTime:"", 
                    ArrivalTime:"", 
                }
            });   
            
            //转出输入验证 01-03
            var validate = $("._transfer").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form  
                    AddTransfer();//转出
                },
                rules: {                    
                    Balance: "required", 
                    BankID:"required", 
                    ExAmount:"required",   
                    ArrivalTime:"required",
                    Comments:"required",
                },
                messages: {
                    Balance: "",
                    BankID:"",
                    ExAmount:"",  
                    ArrivalTime:"", 
                    Comments:"",
                }
            });   

			
			//申请收支输入验证 12-8 class=_addflow
            var validate = $("._addflow").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                errorPlacement : function(error, element) { 
                    if (element.is(":radio")) 
                        error.appendTo(element.parent().parent()); 
                    else if (element.is(":checkbox")) 
                        error.appendTo(element.parent().parent()); 
                    else 
                        error.appendTo(element.parent().next()); 
                },//调radio
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form   
                    AddFlow();//申请流水
                },
                rules: {
                    Remarks: "required", 
                    Account:"required", 
                    ArrivalTime: "required", 
                    Type: "required",
                    Amount: "required",
                },
                messages: {
                    Amount:"",
                    Remarks: "",
                    Account:"账户必选",
                    ArrivalTime:"",
                    Type:"收支必选",
                }
            });

            //修改输入验证 12-8 class=_mod
            var validate = $("._mod").validate({
                debug: true, //调试模式取消submit的默认提交功能   
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应  
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form   
                    EditBank();//结余调节
                },
                rules: {
                    BankBalance:"required", 
                    BankAccount:"required", 
                    BankName:"required", 
                    Comments:"required", 
                    Currency:"required",
                },
                messages: {
                    BankBalance:"",
                    BankAccount:"", 
                    BankName:"", 
                    Comments:"",
                    Currency:"",
                }
            });


			
		},
	

	}
	apply.init();
})();

		//获取参数
        function getParamer(){
            var requestBanks = {};
            requestBanks.BankName =$.trim($("#_name").val());
            requestBanks.BankAccount =$.trim($("#_account").val());
            requestBanks.CheckResult = $("#_checkresult").val();
            requestBanks.Currency = $("#sel_currency").val();            
            requestBanks.Status = $("#_status").val();
            requestBanks.SCreateTime = $("#screatetime").val();
            requestBanks.ECreateTime = $("#ecreatetime").val();

            requestBanks.SCheckTime = $("#schecktime").val();
            requestBanks.ECheckTime = $("#echecktime").val();

            requestBanks.PageSize = 500; //id=_pageSizes
            requestBanks.PageIndex = 1;//.page_num是class
            return requestBanks;
        }
		 //加载
         function LoadBanks(p) {
        	var self = this;
        	myApp.showIndicator();//显示加载中
            if(p){
                var requestBanks=p;
            }else{
                if(b_lang==1){
                    var requestBanks = getParamer();
                    requestBanks.OperationModel  = lang;
                }else{
                    var requestBanks = getParamer(requestBanks);
                }
            }

            if(RoleID == 1 || RoleID == 2){

                $.ajax({
                    url: "/Team/GetBanks",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBanks),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                    	var _result = eval('(' + result + ')');//eval()解析单个json对象
			
			            if (_result.msgcode == false) {
			            	
			                var tr = "";//单行
			                var tds = "<td colspan='9' style='text-align:center;color:red'>" + _(_result.msginfo) + "</td>";// 多列合成一列并居中
			                tr = "<tr>" + tds + "</tr>";//将多列加到一行
			                $("#stock_body").html(tr);//加入到id为customer的table的tbody中
			                myApp.hideIndicator();  //数据加载完成后去除全屏遮罩层
			            } else {
			            	_result = _result.msginfo.Data;//object
			            	SortJson = _result;
			            	BindingData(_result, $("#stock_body"));//绑定数据
			            }
                       
                        myApp.hideIndicator();
                    }
                });
            }else{
                var tr = "";//单行
                var tds = "<td colspan='23' style='text-align:center;color:red'>"+_("没有任何记录")+"</td>";// 多列合成一列并居中
                tr = "<tr>" + tds + "</tr>";//将多列加到一行
                $("#stock_body").html(tr);//加入到id为banks的table的tbody中
                myApp.hideIndicator();  //数据加载完成后去除全屏遮罩层 
            }
        }

        //绑定数据
        function BindingData(_result, tableTbody) {
        	myApp.showIndicator();
               
                var trs = "";//多行数据
                for (var i = 0; i < _result.length; i++) {
					
                    var tds = "";//多列
                    var tr = "";//单行
                    var tr_div = "";
                    var btn = "";
                    
					tds += "<td>" + (i + 1) + "</td>";
                    tds += "<td>" + _(_result[i].BankName) + "</td>";
                    tds += "<td>" +  NullFormat(_result[i].BankAccount) + "</td>";
                    tds += "<td style='font-weight:bold;'>" + _result[i].BankBalance + "</td>";
                    tds += "<td>" + CheckResultFormat(_result[i].CheckResult) + "</td>"; //结余对账
                    tds += "<td>" + NullFormat(_result[i].Checker) + "</td>";  //对账人
                    tds += "<td>" + BankStatusFormat(_result[i].Status) + "</td>";//1启用 0禁用
                    tds += "<td>" + NullFormat(_result[i].Type) + "</td>";//1-2-3
                    
                    //启用Status=1
                    if(_result[i].Status == 1){
                        tds += "<td class='check_toolbtn'>"+
                        "<span class='modify' title='结余调节' onclick='modify_box(this)' value='" + _result[i].BankID + "'>"+_("调节")+"</span></td>"
                        
                    }else{
                        tds += "<td class='check_toolbtn'>"+
                        "<span class='modify' title='启用账户' onclick='Open_Js(this)' value='" + _result[i].BankID + "'>"+_("启用")+"</span></td>";
                    }          
                    
                    tr += "<tr class='data_tr'>" + tds + "</tr>";//将多列加到一行
                    //虚拟账户Type=1
                    if(_result[i].Type == 2 || _result[i].Type == 3 || _result[i].Type == 1 || _result[i].Status == 1){
                       btn = "<i><b>"+_("操作")+"</b><i>"+
                       "<i><span class='modify' title='结余对账' onclick='Check1_Js(this)' value='" + _result[i].BankID + "'>"+_("相符")+"</span>"+
                        "<span class='modify' title='结余对账' onclick='Check0_Js(this)' value='" + _result[i].BankID + "'>"+_("不符？")+"</span></i>"+
                        "<i><span class='modify' title='转账到其他账户' onclick='transfer_box(this)' value='" + _result[i].BankID + "' currency='"+_result[i].Currency+"'>"+_("转出")+"</span>"+
                        "<span class='modify' title='查询"+ _result[i].BankName +"明细' onclick='CheckFlow_Js(" + _result[i].BankID + ")' value='" + _result[i].BankID + "'>"+_("明细")+"</span></i>";
                    }
                    if(_result[i].Type == 3){
                        btn +="<i><span class='modify' title='定货账户入账' onclick='exchange_box(this)' value='" + _result[i].BankID + "'>"+_("兑换美金")+"</span></i>";
                    }else if(_result[i].Type == 1){
                       btn +="<i><span class='modify' style='width:auto' title='账户充值' onclick='rechange_box(this)' value='" + _result[i].BankID + "'>"+_("直接充值")+"</span></i>";
                    }
                    //启用Status=1
                    else if(_result[i].Status == 1){
                        btn +="<i><span class='modify' title='禁用账户' onclick='Set_Js(this)' value='" + _result[i].BankID + "'>"+_("禁用")+"</span></i>";
                    }
                    else{
                    	btn ="<i></i>";
                    }
                    tr_div="<tr class='stock_detail'><td  colspan='9'>"+
                    "<div class='detail_left' style='width:50%;'>"+
                        "<i><b>"+_("币种")+"：</b>"+CurrencyFormat(_result[i].Currency)+"</i>"+
                        "<i><b>"+_("结余更新")+"：</b>" + DateTimeFormat(_result[i].UpdateTime) + "</i>"+
                        "<i><b>"+_("加入时间")+"：</b>" + DateTimeFormat(_result[i].CreateTime) + "</i>"+
                        "<i><b>"+_("对账时间")+"：</b>" +  DateTimeFormat(_result[i].CheckTime) + "</i>"+
                        "<i><b>"+_("备注")+"：</b>" +  NullFormat(_result[i].Comments) + "</i>"+
                    "</div>" +
                    "<div class='detail_middle' style='width:50%;'>"+btn+       	
                    "</div></td></tr>";
                    
                    trs += tr+tr_div;//将单行加到多行 
                    
                }
                $("#stock_body").html(trs);//加入到id为customer的table的tbody中
                myApp.hideIndicator();  //数据加载完成后去除全屏遮罩层
//          }
        }

        //相符CheckResult = 1
        function Check1_Js(me) {
        	
			myApp.confirm(_('确定【相符】?'), '', function () {
				requestBank = {};
                requestBank.BankID = me.getAttribute("value");
                requestBank.CheckResult = 1;//1相符 0 不相符
                requestBank.UserID = UserID;//对账人

                $.ajax({
                    url: "/Team/EditBank",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBank),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');

                        if (_result.msgcode == true) {
                            LoadBanks();
                        } else {
                            myApp.alert(_result.msginfo);
                        }
                    }
                });
			});

        }

        //启用 Status = 1
        function Open_Js(me){
		    myApp.confirm(_('确定【启用】?'), '', function () {
		         requestBank = {};
                requestBank.BankID = me.getAttribute("value");
                requestBank.Status = 1;//0禁用 1启用
                requestBank.UserID = UserID;//对账人

                $.ajax({
                    url: "/Team/EditBank",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBank),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');

                        if (_result.msgcode == true) {
                            LoadBanks();
                        } else {
                            myApp.alert(_(_result.msginfo));
                        }
                    }
                });
		    });
        }

        //禁用Status = 0
        function Set_Js(me){
        	myApp.confirm(_('确定【禁用】?'), '', function () {
		        requestBank = {};
                requestBank.BankID = me.getAttribute("value");
                requestBank.Status = 0;//0禁用 1启用
                requestBank.UserID = UserID;//对账人

                $.ajax({
                    url: "/Team/EditBank",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBank),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');

                        if (_result.msgcode == true) {
                        	myApp.alert(_(_result.msginfo));
                            LoadBanks();
                        } else {
                            myApp.alert(_(_result.msginfo));
                        }
                    }
                });
		    });
        	
        }

        //不相符CheckResult = 0
        function Check0_Js(me) {
        	myApp.confirm(_('确定【不相符】?'), '', function () {
		        requestBank = {};
                requestBank.BankID = me.getAttribute("value");
                requestBank.CheckResult = 0;//1相符 0 不相符
                requestBank.UserID = UserID;//对账人

                $.ajax({
                    url: "/Team/EditBank",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBank),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');

                        if (_result.msgcode == true) {
                            LoadBanks();
                        } else {
                            myApp.alert(_(_result.msginfo));
                        }
                    }
                });
		    });
        	
        }

        //余额调节(默认不符0)
        function EditBank() {
        	myApp.confirm(_('确定【结余调节】?'), '', function () {
		        requestBank = {};

                requestBank.BankID = $("#_bankID").val();
                requestBank.BankBalance = $("#_bankBalance").val();
                requestBank.Currency = $("#_currency option:checked").val();//下拉框
                requestBank.Comments = $("#_comments").val();                
                requestBank.BankName = $("#_bankName").val();
                requestBank.BankAccount = $("#_bankAccount").val();            
                requestBank.CheckResult = 0;//不符0
                requestBank.UserID = UserID;//对账人

                $.ajax({
                    url: "/Team/EditBank",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestBank),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');

                        if (_result.msgcode == true) {
                            $(".modify_pop_box").hide();
                            LoadBanks();
                        } else {
                            myApp.alert(_(_result.msginfo));
                        }
                    }
                });
		    });

        }

        //结余调节弹出框
        function modify_box(me) {
            $(me).css("background-position", "-28px -103px");

            myApp.popup(".modify_pop_box");

            $(".pop .colse_popbox").click(function () {
                $(".modify_pop_box").hide();
                $(".modify").css("background-position", "-28px -74px");
            });

            $.ajax({
                url: "/Team/GetBank",//提交地址
                type: "POST",//提交方式
                data: "{'BankID':'" + me.getAttribute("value") + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    $("#_bankID").val(_result.BankID);
                    $("#_bankName").val(_result.BankName);                   
                    $("#_bankBalance").val(_result.BankBalance);
                    $("#_comments").val(_result.Comments);                    
                    $("#_bankAccount").val(_result.BankAccount);
                    $("#_currency").val(_result.Currency);
                }
            });
        }       
       

        //导出账户 12-3
        function ExportBanks(){
            var requestBanks =  getParamer();//获取所有参数

            $.ajax({
                url: "/Team/ExportBanks",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestBanks),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    if (_result.msgcode == true) {
                        window.open(_result.msginfo);//打开文件
                        myApp.alert(_("充值导出成功.如未自动下载，请查看文件是否被浏览器拦截。"));
                    } else {
                        myApp.alert(_result.msginfo);
                    }
                }
            });
        }

        //直接充值 01-05
        function rechange_box(me){
            myApp.popup(".rechange_pop_box");

            $(".pop .colse_popbox").click(function () {
                $(".rechange_pop_box").hide();
            });

            $.ajax({
                url: "/Team/GetBank",//提交地址
                type: "POST",//提交方式
                data: "{'BankID':'" + me.getAttribute("value") + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    $("#re_bankName").val(_result.BankName); 
                    $("#re_bankID").val(_result.BankID);
                    $("#re_bankBalance").val(_result.BankBalance);                    
                }
            });
        }

        //换美金 01-03
        function exchange_box(me){
        	myApp.popup(".exchange_pop_box");

            //LastExchange();//上次兑换汇率 01-04

            AccountLoad();//01-04 支出账户下拉列表

            $(".pop .colse_popbox").click(function () {
                $(".exchange_pop_box").hide();
            });

            $.ajax({
                url: "/Team/GetBank",//提交地址
                type: "POST",//提交方式
                data: "{'BankID':'" + me.getAttribute("value") + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    //$("#_exbankName").val(_result.BankName); 
                    $("#_exbankID").val(_result.BankID);
                    $("#_balance").val(_result.BankBalance);                    
                }
            });
        }

        //转账到
        function transfer_box(me){

            myApp.popup(".transfer_pop_box");
    
            $(".pop .colse_popbox").click(function () {
                $(".transfer_pop_box").hide();
            });

            $.ajax({
                url: "/Team/GetBank",//提交地址
                type: "POST",//提交方式
                data: "{'BankID':'" + me.getAttribute("value") + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    $("#_transferbankName").val(_result.BankName); 
                    $("#_transferbankID").val(_result.BankID);
                    $("#transfer_balance").val(_result.BankBalance);                    
                }
            });

            $.ajax({
                url: "/Team/GetBankList",//提交地址
                type: "POST",//提交方式
                async: false, //异步 9-27
                data: "{'Status':'" + 1 + "','Currency':'" + me.getAttribute("currency") + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    if (_result.msgcode == false) {

                        var options = "";
                        options += '<option value="">' + _result.msginfo + '</option>';
                        $("#transfer_accountID").html("");//账户下拉
                        $("#transfer_accountID").html(options);
                        

                    } else {

                        var options = "";
                        options += '<option value="">支出账户</option>';
                        for (var i = 0; i < _result.length; i++) {
                            options += '<option value="' + _result[i].BankID + '"  >' + _result[i].BankName + '</option>';
                        }
                        $("#transfer_accountID").html("");//账户下拉
                        $("#transfer_accountID").html(options);
                    }
                }
            });
        }

        //申请流水
        //添加流水
        function AddFlow(){

            var requestFlow = {};

            requestFlow.Remarks = $("#remarks").val();
            //requestFlow.Comments = $("#comments").val();

            requestFlow.Others = $("#others").val();
            requestFlow.Amount = $("#amount").val();
            requestFlow.ArrivalTime = $("#arrivalTime").val();
            requestFlow.Purpose = $("#purpose option:checked").val();
            requestFlow.Currency = $("#apply_currency option:checked").val();
            //requestFlow.Account = $("#account option:checked").val();//下拉框
            //requestFlow.Account =$('input:radio[name="Account"]:checked').val();//单选框 -静态
            requestFlow.Account =$('#_bankID1 input:radio[name="Account"]:checked').val();//单选框 -动态 12-23

            requestFlow.Status = $("#status option:checked").val();

            //requestFlow.Type = $("#type option:checked").val();//1收入 2支出
            requestFlow.Type =$('input:radio[name="Type"]:checked').val();//单选框
            requestFlow.Abstract =$('input:radio[name="Abstract"]:checked').val();//单选框

            requestFlow.ApplyID = UserID //申请人ID
            //requestFlow.ReviewID = UserID //审核人ID
                
            $.ajax({
                url: "/Team/AddFlowByPassStatus",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestFlow),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象 
                    if(_result.msgcode == true){
                        myApp.alert(_result.msginfo,function(){
                        	myApp.closeModal(".applyflow_pop_box");
                        });
                        
                    }else{
                        myApp.alert(_result.msginfo);
                    }

                }
            });
        }

        //添加流水账户列表 12-23
        function TjAccountLoad() {

            var requestAccount = {};

            requestAccount.Status = 1;//启用1

            requestAccount.Type ='2,3';

            $.ajax({
                url: "/Team/GetBankList",//提交地址
                type: "POST",//提交方式
                async: false, //异步 9-27
                data: JSON.stringify(requestAccount),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    if (_result.msgcode == false) {
                        var options = "";
                        options += '<lable>' + _result.msginfo + '</label>';
                        $("#_bankID1").html("");//账户下拉
                        $("#_bankID1").html(options);
                    } else {
                        var options = "";
                        for (var i = 0; i < _result.length; i++) {
                            options += '<div><input type="radio" name="Account" value="' + _result[i].BankID + '" id="czaccout' + i + '" /><label for="czaccout' + i + '">' + _result[i].BankName + '</label></div>';
                        }
                        $("#_bankID1").html("");//账户下拉
                        $("#_bankID1").html(options);
                    }
                }
            });
        }

        //申请流水弹出框
//      function applyflow_box(){
//          myApp.showIndicator(".applyflow_pop_box")
//          TjAccountLoad();//账户列表
//      }

        //添加账户弹出框
//      function add_box() {
//      	myApp.showIndicator(".add_pop_box");
//      } 
        
        //添加流水
        function AddBank(){

            var requestBank = {};

            requestBank.BankName = $("#bankName").val();
            requestBank.BankAccount = $("#bankAccount").val();
            requestBank.BankBalance = $("#bankBalance").val();
            requestBank.Currency = $("#currency option:checked").val();//下拉框

            requestBank.UserID = UserID;

            $.ajax({
                url: "/Team/AddBank",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(requestBank),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    if(_result.msgcode == true){
                        $(".add_pop_box input[type=reset]").trigger("click");

                        myApp.alert(_result.msginfo);
                        $(".add_pop_box").hide();
                        LoadBanks();//加载
                    }else{
                        myApp.alert(_result.msginfo);
                    }

                }
            });
        }

        //可兑换美金
        function ComputeUsd(){
            
            var _a = $("#ex_exAmount").val();//实支出金额
            var _b = $("#ex_exchange").val();//兑换汇率
         
            $("#_actualAmount").val(($("#ex_Amount").val() * $("#ex_exchange").val()));//应支出金额 = 已兑换美金 * 兑换汇率

            if(Number(_a / _b) >= 0){
                $("#ex_exBalance").val((_a / _b).toFixed(3));//可兑换美金
            }else{
                $("#ex_exBalance").val();//可兑换美金
                myApp.alert("无法计算【可兑换美金】：\n\n 可兑换美金 = 实支出金额 / 兑换汇率");
            }
        }


        //添加兑换
        function AddExchange(){

            ComputeUsd();//推算
            
            myApp.confirm('确定兑换美金？', 'Custom Title', function () {
		        var requestEx = {};

                requestEx.ExBankID = $("#_exbankID").val();//收入账户
                requestEx.BankID = $("#mod_accountID option:checked").val();//支出账户    
                requestEx.Others = $("#ex_others").val();//人物                
                requestEx.Exchange = $("#ex_exchange").val();
                requestEx.Comments = $("#ex_remarks").val();  
                requestEx.ExBalance = $("#ex_exBalance").val();
                requestEx.Amount = $("#ex_Amount").val();//应支出   
                requestEx.ExAmount = $("#ex_exAmount").val();//实支出
                requestEx.CreateTime = $("#ex_createTime").val();//兑换日期 2017-02-23 
                requestEx.ArrivalTime = $("#ex_arrivalTime").val();//兑换到账日期 2017-03-06
                requestEx.UserID = UserID;

                $.ajax({
                    url: "/Team/ModifyExchange",//提交地址  AddExchange
                    type: "POST",//提交方式
                    data: JSON.stringify(requestEx),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象

                        if(_result.msgcode == true){
                            $(".exchange_pop_box input[type=reset]").trigger("click");

                            myApp.alert(_result.msginfo);
                            $(".exchange_pop_box").hide();
                            LoadBanks();//加载
                        }else{
                            myApp.alert(_result.msginfo);
                        }

                    }
                });
		    });
        }

        //转出
        function AddTransfer(){
        	
        	myApp.confirm('确定转出吗？', '', function () {
		        var requestTransfer = {};

                    requestTransfer.ExBankID = $("#_transferbankID").val();//转出账户
                    requestTransfer.BankID = $("#transfer_accountID option:checked").val();//转入账户    
                    requestTransfer.Comments = $("#transfer_remarks").val();  
                    requestTransfer.ExAmount = $("#transfer_exAmount").val();//实支出/转出金额
                    requestTransfer.ArrivalTime = $("#transfer_arrivalTime").val();//到账日期  
                    requestTransfer.UserID = UserID;

                    $.ajax({
                        url: "/Team/BankTransfer",//提交地址  BankTransfer
                        type: "POST",//提交方式
                        data: JSON.stringify(requestTransfer),
                        contentType: "application/json; charset=utf-8",
                        success: function (result) {
                            var _result = eval('(' + result + ')');//eval()解析单个json对象

                            if(_result.msgcode == true){
                                $(".transfer_pop_box input[type=reset]").trigger("click");

                                myApp.alert(_result.msginfo);
                                $(".transfer_pop_box").hide();
                                LoadBanks();//加载
                            }else{
                                myApp.alert(_result.msginfo);
                            }

                        }
                    });
		    });
        }

        //直接账户充值 01-05
        function DirectCharge(){
        	
        	myApp.confirm('确定直接充值？', '', function () {
		         var requestDirect = {};

                requestDirect.BankID = $("#re_bankID").val();
                requestDirect.Purpose = $("#re_purpose option:checked").val();
                requestDirect.Amount = $("#re_amount").val();
                requestDirect.Comments = $("#re_remarks").val();
                requestDirect.Others = $("#re_others").val();            
                requestDirect.UserID = UserID;            

                $.ajax({
                    url: "/Team/DirectCharge",//提交地址
                    type: "POST",//提交方式
                    async: false, //异步 9-27
                    data: JSON.stringify(requestDirect),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象

                        if(_result.msgcode == true){
                            myApp.alert(_result.msginfo);
                            $(".rechange_pop_box input[type=reset]").trigger("click");
                            $(".rechange_pop_box").hide();
                            LoadBanks();//加载
                        }else{
                            myApp.alert(_result.msginfo);
                        }
                    }
                });
		    });

        }

        //支出账户下拉列表 01-04
        function AccountLoad() {

            var requestAccount = {};

            requestAccount.Status = 1;//启用1

            $.ajax({
                url: "/Team/GetBankList",//提交地址
                type: "POST",//提交方式
                async: false, //异步 9-27
                data: JSON.stringify(requestAccount),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象

                    if (_result.msgcode == false) {

                        var options = "";
                        options += '<option value="">' + _result.msginfo + '</option>';
                        $("#mod_accountID").html("");//账户下拉
                        $("#mod_accountID").html(options);                        

                    } else {

                        var options = "";
                        options += '<option value="">支出账户</option>';
                        for (var i = 0; i < _result.length; i++) {
                            options += '<option value="' + _result[i].BankID + '"  >' + _result[i].BankName + '</option>';
                        }

                        $("#mod_accountID").html("");//账户下拉
                        $("#mod_accountID").html(options);
                    }
                }
            });
        }



        //查询明细
        function CheckFlow_Js(bankid) {
            if (bankid != "") {
                $.cookie("_bankid", bankid, 1, "/");
                location.href = "/team/flow";
            }
        }

        //对账记录
        function CheckResultFormat(checkValue) {
            if (checkValue == 0) {
                return "<b style='color:red;'>"+_("不符")+"</b>";
            } else if (checkValue == 1) {
                return _("相符");
            } else {
                return _("未对账");
            }
        }

        //状态格式化
        function BankStatusFormat(statusValue){
            if (statusValue == 1) {
                return _("启用");
            } else if (statusValue == 0) {
                return "<b style='color:red;'>"+_("禁用")+"</b>";
            } else {
                return statusValue;
            }
        } 
    
        


        